From: Bastien Nocera Date: Wed, 19 Oct 2016 13:58:16 +0000 (+0200) Subject: appDisplay: Add a menu item to launch on the discrete GPU X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~674 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=009d021e4f93bfce69d1f4497612d804c88972b6;p=gnome-shell.git appDisplay: Add a menu item to launch on the discrete GPU It will only show up when a discrete GPU is available (detected through the switcheroo-control D-Bus service), and the application hasn't alreayd been launched. Note that this will not currently work for D-Bus activated applications, eg. the menu item will be available, but the environment variable will not be passed through to D-Bus to use when launching the application. https://bugzilla.gnome.org/show_bug.cgi?id=773117 --- diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index cae175709..f81ab593e 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -60,6 +60,18 @@ const PAGE_SWITCH_TIME = 0.3; const VIEWS_SWITCH_TIME = 0.4; const VIEWS_SWITCH_ANIMATION_DELAY = 0.1; +const SWITCHEROO_BUS_NAME = 'net.hadess.SwitcherooControl'; +const SWITCHEROO_OBJECT_PATH = '/net/hadess/SwitcherooControl'; + +const SwitcherooProxyInterface = ' \ + \ + \ + \ +'; + +const SwitcherooProxy = Gio.DBusProxy.makeProxyWrapper(SwitcherooProxyInterface); +let discreteGpuAvailable = false; + function _getCategories(info) { let categoriesStr = info.get_categories(); if (!categoriesStr) @@ -969,6 +981,32 @@ const AppDisplay = new Lang.Class({ initialView = Views.ALL; this._showView(initialView); this._updateFrequentVisibility(); + + Gio.DBus.system.watch_name(SWITCHEROO_BUS_NAME, + Gio.BusNameWatcherFlags.NONE, + Lang.bind(this, this._switcherooProxyAppeared), + Lang.bind(this, function() { + this._switcherooProxy = null; + this._updateDiscreteGpuAvailable(); + })); + }, + + _updateDiscreteGpuAvailable: function() { + if (!this._switcherooProxy) + discreteGpuAvailable = false; + else + discreteGpuAvailable = this._switcherooProxy.HasDualGpu; + }, + + _switcherooProxyAppeared: function() { + this._switcherooProxy = new SwitcherooProxy(Gio.DBus.system, SWITCHEROO_BUS_NAME, SWITCHEROO_OBJECT_PATH, + Lang.bind(this, function(proxy, error) { + if (error) { + log(error.message); + return; + } + this._updateDiscreteGpuAvailable(); + })); }, animate: function(animationDirection, onComplete) { @@ -1861,6 +1899,19 @@ const AppIconMenu = new Lang.Class({ this._appendSeparator(); } + if (discreteGpuAvailable && + this._source.app.state == Shell.AppState.STOPPED && + actions.indexOf('activate-discrete-gpu') == -1) { + this._onDiscreteGpuMenuItem = this._appendMenuItem(_("Launch using Dedicated Graphics Card")); + this._onDiscreteGpuMenuItem.connect('activate', Lang.bind(this, function() { + if (this._source.app.state == Shell.AppState.STOPPED) + this._source.animateLaunch(); + + this._source.app.launch(0, -1, true); + this.emit('activate-window', null); + })); + } + for (let i = 0; i < actions.length; i++) { let action = actions[i]; let item = this._appendMenuItem(appInfo.get_action_name(action));